package com.IntelligenceInsight.Myth.service;

import com.IntelligenceInsight.Myth.mapper.ModelMapper;
import com.IntelligenceInsight.Myth.model.Model;
import com.IntelligenceInsight.Myth.util.NoteRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ModelService {
    @Autowired
    private ModelMapper mapper;

    public NoteRequest ModelAdd(String uuid, String name, String owner, String description) {
        NoteRequest res = new NoteRequest();
        int n = mapper.ModelAdd(uuid, name, owner, description);
        if(n < 1) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success: " + uuid);
        }
        return res;
    }

    public NoteRequest ModelUpdate(String uuid, int lastVersion, int version, String modelString) {
        NoteRequest res = new NoteRequest();
        int n = mapper.ModelUpdate(uuid, lastVersion, version, modelString);
        if(n < 1) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success: " + uuid);
        }
        return res;
    }


    public NoteRequest ModelListByOwner(String owner) {
        NoteRequest res = new NoteRequest();
        List<Model> model = mapper.ModelListByOwner(owner);
        if(model == null) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
            res.setData(model);
        }
        return res;
    }

    public NoteRequest ModelListAll(int page,int limit) {
        NoteRequest res = new NoteRequest();
        List<Model> model = mapper.ModelListAll(page,limit);
        if(model == null) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
            res.setData(model);
        }
        return res;
    }

    public NoteRequest ModelListAllforName() {
        NoteRequest res = new NoteRequest();
        List<Model> model = mapper.ModelListAllforName();
        if(model == null) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
            res.setData(model);
        }
        return res;
    }

    public int ModelListAllCount() {
        NoteRequest res = new NoteRequest();
       int count = mapper.ModelListAllCount();
       return count;
    }

    public NoteRequest ModelByUuid(String uuid) {
        NoteRequest res = new NoteRequest();
        Model model = mapper.ModelByUuid(uuid);
        if(model == null) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
            res.setData(model);
        }
        return res;
    }

    public NoteRequest ModelByName(String name) {
        NoteRequest res = new NoteRequest();
        Model model = mapper.ModelByName(name);
        if(model == null) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
            res.setData(model);
        }
        return res;
    }


    public NoteRequest ModelRemoveByName(String name) {
        NoteRequest res = new NoteRequest();
        int n = mapper.ModelRemoveByName(name);
        if(n < 1) {
            res.setStatus(1);
            res.setMsg("failure");
        } else {
            res.setStatus(0);
            res.setMsg("success");
        }
        return res;
    }



}
